package managers.conversationManager;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

import managers.messengerManager.services.Service;

public class ConversationManager {

	private static ConversationManager sharedInstance = new ConversationManager();
	
	private HashMap<String, Service> services = new HashMap<String, Service>();
	
	private ConversationProtocol protocol;
	private FloatingChatsManager chatManager;
	private UserRequestsManager userRequestManager;

	
	
	private ConversationManager() {
	}

	public void setParameters (ConversationProtocol protocol, FloatingChatsManager chatManager, UserRequestsManager userRequestManager) {
		this.protocol = protocol;
		this.chatManager = chatManager;
		this.userRequestManager =userRequestManager;
	}
	
	public void addService (Service service) {
		services.put(service.getName(), service);
	}
	
	public void start () {
		Collection<Service> s = services.values();
		Iterator<Service> it = s.iterator();
		while (it.hasNext()) {
			it.next().start();
		}
	}
	
	public void close () {
		chatManager.closeAllConnections();
		protocol.close();
	}
	
	
	public static ConversationManager getSharedInstance() {
		return sharedInstance;
	}

	public FloatingChatsManager getChatManager() {
		return chatManager;
	}


	public ConversationProtocol getProtocol() {
		return protocol;
	}


	public UserRequestsManager getUserRequestsManager() {
		return userRequestManager;
	}


}
